package com.cjx.print.utils;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.cjx.print.App;
import com.cjx.print.R;


/**
 * Created by bpb on 2019/10/21.
 * 说明：
 */
public class ToastUtil {

    private final TextView tipView;

    private final Toast toast;

    private static final class UtilHolder {
        static final ToastUtil util = new ToastUtil();
    }

    public static ToastUtil getInstance() {
        return UtilHolder.util;
    }

    private ToastUtil() {
        View view = LayoutInflater.from(App.app).inflate(R.layout.layout_toast, null);
        tipView = view.findViewById(R.id.toast_tips);

        toast = new Toast(App.app);
        toast.setView(view);
        toast.setGravity(Gravity.CENTER, 0, 0);
    }

    public void showText(String text) {
        this.showText(text, Toast.LENGTH_SHORT);
    }

    public void showTextLong(String text) {
        this.showText(text, 5000);
    }

    public void showText(String text,  int duration) {
        tipView.setText(text);
        toast.setDuration(duration);
        toast.show();
    }

}
